<template>
  <div class="app-container container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="采集时刻">
        <el-date-picker
          v-model="daterangeClTime"
          size="small"
          style="width: 340px"
          value-format="yyyy-MM-dd HH:mm:ss"
          format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          popper-class="custom-class"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="测点状态" prop="cdStatus">
        <el-select
          v-model="queryParams.cdStatus"
          placeholder="请选择测点状态"
          clearable
          size="small"
          @change="handleQuery"
          popper-class="selectcss"
        >
          <el-option
            v-for="dict in measurePointStatusList"
            :key="dict.statusValue"
            :label="dict.csStatusName"
            :value="dict.statusValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search" circle
          size="mini"
          @click="handleQuery"
          ></el-button
        >
        <el-button icon="el-icon-refresh" size="mini" circle type="warning" @click="resetQuery"
          ></el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="rainRealDataList"
      :row-class-name="tableRowClassNameT"
    >
      <el-table-column label="序号" width="80" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="测点编码" align="center" prop="cdCode" />
      <el-table-column label="清空时间" align="center" prop="clearTime">
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.clearTime, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="测量时间" align="center" prop="clTime">
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.clTime, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="采集时刻"
        align="center"
        prop="cjTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.cjTime, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="测点状态"
        align="center"
        prop="cdStatus"
        :formatter="cdStatusFormatter"
      >
        <template slot-scope="scope">
          <i
            :class="scope.row.cdStatus | caseStatusColorFilter"
            class="el-icon-star-on"
          ></i
          ><span :class="scope.row.cdStatus | caseStatusColorFilter">{{
            cdStatusFormatter(scope.row.cdStatus)
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数值" align="center" prop="cjValue" />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
      class="page"
    />
  </div>
</template>

<script>
import { listRainRealData } from "@/api/realData/rainRealData";
import { listMeasurePointStatus } from "@/api/dictData/measurePointStatus";
import "../../../assets/styles/time.css";
export default {
  name: "RainRealData",
  props: {
    parenttime: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 降水量监测实时信息表格数据
      rainRealDataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 测量时间时间范围
      daterangeClTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mineCode: null,

        mineName: null,

        cdCode: null,

        clearTime: null,

        clTime: null,

        cjTime: null,

        cdStatus: null,

        cjValue: null
      },
      // 表单参数
      form: {},
      //测点状态
      measurePointStatusList: [],
      stime: "",
      etime: ""
    };
  },
  created() {
    if(this.parenttime == '0'){
      this.stime = this.getCurDate() + " " + "00:00:00";
      this.etime = this.getCurDate() + " " + "23:59:59";
      this.daterangeClTime.push(this.stime);
      this.daterangeClTime.push(this.etime);
    }else{
      this.daterangeClTime=[]
    }
    
    this.getList();
    listMeasurePointStatus().then(response => {
      this.measurePointStatusList = response.rows;
    });
  },
  methods: {
    tableRowClassNameT({ rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "evencolort";
      } else {
        return "oddcolort";
      }
    },
    /** 查询降水量监测实时信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeClTime && "" != this.daterangeClTime) {
        this.queryParams.params["beginCjTime"] = this.daterangeClTime[0];
        this.queryParams.params["endCjTime"] = this.daterangeClTime[1];
      }
      listRainRealData(this.queryParams).then(response => {
        this.rainRealDataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,

        mineCode: null,

        mineName: null,

        cdCode: null,

        clearTime: null,

        clTime: null,

        cjTime: null,

        cdStatus: null,

        cjValue: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeClTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>
